package com.rover022.flixelgame.ui.battle
{
	import com.greensock.events.LoaderEvent;
	import com.greensock.loading.LoaderMax;
	import com.rover022.flixelgame.manager.AssetManager;
	import com.rover022.flixelgame.manager.EventHelper;
	import com.rover022.flixelgame.manager.PlayerManager;
	import com.rover022.flixelgame.manager.WorldManager;
	import com.rover022.flixelgame.ui.BaseUI;
	import com.rover022.flixelgame.vo.UserVo;
	import com.rover022.flixelgame.world.CityState;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import de.polygonal.core.fmt.NumberFormat;

	/**
	 * 战场信息UI
	 * @author flashpig
	 *
	 */
	public class BattleInfoUI extends BaseUI
	{
		public var swfId:String = "ui/BattleUI.swf";
		public var classId:String = "assets.baseui.battleui";

		public function BattleInfoUI()
		{
			super();
			trace(LoaderMax.getContent(swfId))
			trace(LoaderMax.getContent(classId))
			AssetManager.getInstance().loadAssetArray([swfId], initUI);
		}

		override public function initUI(e:LoaderEvent = null):void
		{
			assetUI = AssetManager.getInstance().requestAssetInstance(swfId, classId);
			var _userVo:UserVo = PlayerManager.getInstance().getUserVo();
			_userVo.register(this);
			EventHelper.addEventListener(backButton, MouseEvent.CLICK, backClick);
			//backButton.addEventListener(MouseEvent.CLICK, backClick);
			addChild(assetUI);
		}

		override public function dispose():void
		{
			var _userVo:UserVo = PlayerManager.getInstance().getUserVo();
			_userVo.unregister(this);
			assetUI = null;
		}

		/**
		 * 点击返回城市
		 * @param event
		 *
		 */
		protected function backClick(event:Event):void
		{
			var state:CityState = new CityState();
			WorldManager.getInstance().gotoWorld(WorldManager.CITY, state);
		}

		private function get backButton():DisplayObject
		{
			return assetUI.getChildByName("backButton");
		}

		private function get timeMc():MovieClip
		{
			return assetUI.getChildByName("timeMc") as MovieClip;
		}

		private function get gemMc():MovieClip
		{
			return assetUI.getChildByName("boxMc") as MovieClip;
		}

		private function get goldMc():MovieClip
		{
			return assetUI.getChildByName("goldMc") as MovieClip;
		}

		private function get roundMc():MovieClip
		{
			return assetUI.getChildByName("roundMc") as MovieClip;
		}

		/**
		 * 更新时间;
		 * @param num
		 *
		 */
		public function updateTime(num:Number):void
		{
		 
			if (timeMc)
			{
				
				timeMc.numTxt.text = NumberFormat.toMMSS(num*1000);
			}
		}

		/**
		 * 更新金钱
		 * @param num
		 *
		 */
		public function updateGoldMc(num:Number):void
		{
			if (goldMc)
			{
				goldMc.txtNum = num.toString();
			}
		}

		/**
		 * 更新回合数目
		 * @param num
		 *
		 */
		public function updateRoundMc(num:Number):void
		{
			if (goldMc)
			{
				goldMc.txtNum = num.toString();
			}
		}
		
		/**
		 * 更新宝箱数目
		 * @param num
		 *
		 */
		public function updateGemMc(num:Number):void
		{
			if (gemMc)
			{
				gemMc.txtNum = num.toString();
			}
		}
	}
}
